package com.seadragon.app.ksr.model.tiger;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedNativeQueries;
import javax.persistence.NamedNativeQuery;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Type;

import com.seadragon.app.ksr.model.AddressType;
import com.vividsolutions.jts.geom.MultiPolygon;

@Entity
@Table(name = "PLACE", schema = "TIGER")
@NamedNativeQueries({ @NamedNativeQuery(name = "findAdjacentPlaces", query = "select b.* from tiger.place a inner join tiger.place b on ST_DWithin(a.the_geom, b.the_geom, 0.01) where a.name=:placeName and a.statefp=:statefp", resultClass = Place.class) })
public class Place extends Location {
	@Id
	@Column(name = "GID", updatable = false, insertable = false)
	private long id;

	@Column(name = "STATEFP", updatable = false, insertable = false)
	private String statefp;

	@Column(name = "PLACEFP", updatable = false, insertable = false)
	private String placefp;

	@Column(name = "PLCIDFP", updatable = false, insertable = false)
	private String geoid;

	@Column(name = "NAME", updatable = false, insertable = false)
	private String name;

	@Column(name = "CLASSFP", updatable = false, insertable = false)
	private String classfp;

	@Column(name = "FUNCSTAT", updatable = false, insertable = false)
	private String funcStat;

	@Column(name = "INTPTLAT", updatable = false, insertable = false)
	private String intptlat;

	@Column(name = "INTPTLON", updatable = false, insertable = false)
	private String intptlon;

	@Column(name = "THE_GEOM", updatable = false, insertable = false)
	@Type(type = "org.hibernate.spatial.GeometryType")
	private MultiPolygon geom;

	@Transient
	private String state;
	
	public Place(String placeName, String state) {
		this.name = placeName;
		this.state = state;
	}

	public String getIntptlat() {
		return intptlat;
	}

	public void setIntptlat(String intptlat) {
		this.intptlat = intptlat;
	}

	public String getIntptlon() {
		return intptlon;
	}

	public void setIntptlon(String intptlon) {
		this.intptlon = intptlon;
	}

	public void setCounty(String county) {
		this.county = county;
	}

	public Place() {
	}

	@Transient
	private String county;

	public String getCounty() {
		return county;
	}

	public String getGeoid() {
		return geoid;
	}

	public void setGeoid(String geoid) {
		this.geoid = geoid;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getPlacefp() {
		return placefp;
	}

	public void setPlacefp(String placefp) {
		this.placefp = placefp;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getFuncStat() {
		return funcStat;
	}

	public void setFuncStat(String funcStat) {
		this.funcStat = funcStat;
	}

	public String getStatefp() {
		return statefp;
	}

	public void setStatefp(String statefp) {
		this.statefp = statefp;
	}

	public String getClassfp() {
		return classfp;
	}

	public void setClassfp(String classfp) {
		this.classfp = classfp;
	}

	public MultiPolygon getGeom() {
		return geom;
	}

	public void setGeom(MultiPolygon geom) {
		this.geom = geom;
	}

	@Override
	public AddressType getLocationType() {
		return AddressType.CITY;
	}

	@Override
	public Double getLatitude() {
		return null;
	}

	@Override
	public Double getLongitude() {
		return null;
	}

	@Override
	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}
}
